﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.Data.Odbc;
using System.Text;
using System.Web.SessionState;
using System.Web.UI;
using System.Configuration;
using System.Data;
using QualityRpt.Service;
using QualityRpt.Utils;

namespace QualityRPT
{
    /// <summary>
    /// Login1 的摘要说明
    /// </summary>
    public class Login1 : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
          
            string username = context.Request["username"].Trim().ToString();
            string password = context.Request["password"].Trim().ToString();
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] result = Encoding.Default.GetBytes(password);
            byte[] outStr = md5.ComputeHash(result);
            password = BitConverter.ToString(outStr).Replace("-", "");
            DataRow dr = UserService.Get(username, password);
            if (dr!=null)
            {
                context.Session["id"] = dr["id"].ToString();
                context.Session["username"] = dr["username"].ToString();
                context.Session["isadmin"] = dr["isadmin"].ToString();
				AppUtils.SetUser (context.Session, dr.Table);
                context.Response.Redirect("index.aspx?Pid=1&u="+dr["id"].ToString());
            }
            else
            {
                context.Response.Write("<script>alert('对不起，您输入的密码不正确！');location='Login.aspx';</SCRIPT> ");
            }
        }
         

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}